/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package enteties.person.address;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import util.person.address.AddresstypeDetails;

/**
 *
 * @author Gebruiker
 */
@Stateless
public class AddresstypeFacade extends AbstractFacade<Addresstype> implements AddresstypeFacadeLocal {
    @PersistenceContext(unitName = "Liebaut-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public AddresstypeFacade() {
        super(Addresstype.class);
    }
    
    @Override
    public Long createAddressytpe(String name){
        Addresstype addresstype = new Addresstype(name);
        create(addresstype);
        return addresstype.getId();
    }
    
    @Override
    public void editAddresstype(Long id, String name){
        Addresstype addresstype = find(id);
        addresstype.setName(name);
        edit(addresstype);
    }
    
    @Override
    public void removeAddresstype(Long id){
        Addresstype addresstype = find(id);
        remove(addresstype);
    }
    
    @Override
    public AddresstypeDetails getAddresstypeDetails(Long id){
        Addresstype addresstype = find(id);
        return convert(addresstype);
    }
    
    public AddresstypeDetails convert(Addresstype type){
        return new AddresstypeDetails(type.getId(), type.getName());
    }
    
}
